//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace WorkflowApplicationControls
{
    using System.Windows.Controls;
    using System.Windows;
    using WorkflowApplication.Interfaces;
    using WorkflowApplicationModels;

    /// <summary>
    /// Interaction logic for WorkflowTree.xaml
    /// </summary>
    public sealed partial class WorkflowTree : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="WorkflowTree"/> class.
        /// </summary>
        public WorkflowTree()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Called when selected item changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedPropertyChangedEventArgs&lt;System.Object&gt;"/> instance containing the event data.</param>
        private void OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            if (e.NewValue != null)
            {
                BaseModel model = e.NewValue as BaseModel;
                if (model != null)
                {
                    ILeftPanePresenter presenter = this.DataContext as ILeftPanePresenter;
                    if (presenter != null && presenter.ItemSelectedCommand != null)
                    {
                        presenter.ItemSelectedCommand.Execute(model);
                    }
                }
            }
        }
    }
}
